--防护不良
local fanghubuliang = fk.CreateSkill {
    name = "mcdh_fanghubuliang",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

fanghubuliang:addEffect(fk.RoundStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self)
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local choices = {"fanghubuliang1:::"..room:getTag("RoundCount"),"fanghubuliang2:::"..room:getTag("RoundCount")}
        if  room:getTag("RoundCount") > #player:getCardIds("he") then
            table.removeOne(choices,"fanghubuliang1:::"..room:getTag("RoundCount") )
        end
        local choice = room:askForChoice(player, choices, self.name, nil, nil,{"fanghubuliang1:::"..room:getTag("RoundCount"),"fanghubuliang2:::"..room:getTag("RoundCount")})
        if choice == "fanghubuliang1:::"..room:getTag("RoundCount") then
            local _,dat = room:askForUseActiveSkill(player, "mcdh_fanghubuliang_active", "#mcdh_fanghubuliang_active:::"..room:getTag("RoundCount"), false)
            local give = dat.cards
            room:moveCards({
                ids = give ,
                from = player.id,
                to = dat.targets[1] ,
                toArea = Card.PlayerHand,
                moveReason = fk.ReasonGive,
                skillName =  self.name,
                moveVisible = false
            })
            room:setPlayerMark(player,"@@fanghubuliang_damage-round",1)
        elseif choice == "fanghubuliang2:::"..room:getTag("RoundCount") then
            room:handleAddLoseSkills(player,  "-mcdh_fanghubuliang")
            room:loseHp(player,1,self.name)
            player:drawCards(room:getTag("RoundCount"), self.name)
        end
    end
})

fanghubuliang:addEffect(fk.DamageInflicted,{
    can_trigger = function(self, event, target, player, data)
        return player == target and player:getMark("@@fanghubuliang_damage-round") ~= 0 and data.damageType == fk.NormalDamage
    end,
    on_cost = function(self, event, target, player, data)
        return true
    end,
    on_use = function(self, event, target, player, data)
        data.damage = data.damage - 1
    end
})

Fk:loadTranslationTable {
    ["mcdh_fanghubuliang"] = "防护不良",
    [":mcdh_fanghubuliang"] = "锁定技,每轮开始时,你选择一项:1.将X张牌交给一名其他角色,然后本轮内你受到的非属性伤害-1;2.失去本技能和1点体力,然后摸X张牌(X为当前轮次数)。",
    ["fanghubuliang1"] = "1.将 %arg 张牌交给一名其他角色,然后本轮内你受到的非属性伤害-1",
    ["fanghubuliang2"] = "2.失去本技能和1点体力,然后摸 %arg 张牌",
    ["#mcdh_fanghubuliang_active"] = "防护不良:将 %arg 张牌交给一名其他角色",
    ["@@fanghubuliang_damage-round"] = "防护不良",
    ["#mcdh_fanghubuliang_damaga"] = "防护不良",
}

return fanghubuliang